﻿#region Header
// ------------------------ Licence / Copyright ------------------------
// 
// ScrumTable for Scrum Meeting Support
// Copyright © HSR - Hochschule für Technik Rapperswil
// All Rights Reserved
// 
// Author:
//  Michael Gfeller Silvan Gehrig Patrick Boos
// 
// ---------------------------------------------------------------------
#endregion

#region Usings

using System;
using ScrumTable.Common;
using ScrumTable.DL.Data.Generic.Cache;
using ScrumTable.DL.Data.Generic.Properties;
using ScrumTable.DL.Data.Schema;
using ScrumTable.DL.Data.Schema.ScrumTableV1;

#endregion

namespace ScrumTable.DL.Data.Generic
{
    /// <summary>
    /// This class specifies the team data wrapper for a team foundation
    /// server identity.
    /// </summary>
    /// <remarks>The implementation of the data object class follows the Anything pattern.</remarks>
    internal class TeamDataObject : DataObjectBase<TeamSchema, CacheTeam>
    {
        #region Declarations
        //--------------------------------------------------------------------
        // Declarations
        //--------------------------------------------------------------------

        private readonly CacheTeam _data;

        #endregion

        #region Properties
        //--------------------------------------------------------------------
        // Properties
        //--------------------------------------------------------------------

        /// <summary>
        /// Gets the corresponding typed data schema (e.g. UserStorySchema / TaskSchema / ...).
        /// </summary>
        protected override sealed TeamSchema TypedSchema { get { return ScrumTableSchema.TeamSchema; } }

        /// <summary>
        /// Gets the underlying data element instance.
        /// </summary>
        protected override CacheTeam Element { get { return _data; } }

        #endregion

        #region Constructors / Destructor
        //--------------------------------------------------------------------
        // Constructors / Destructor
        //--------------------------------------------------------------------

        /// <summary>
        /// Creates a new TeamDataObject instance, no public constructor
        /// needed.
        /// </summary>
        internal TeamDataObject(
            DataAccessObjectBase parent,
            CacheTeam team)
            : base(parent)
        {
            PreCondition.AssertNotNull(team, "team");

            _data = team;
            _data.PropertyChanged += OnDataPropertyChanged;
            _data.PropertyChanging += OnDataPropertyChanging;

            NameSchemaMappings.Add(TypedSchema.Name, GetName);
        }

        #endregion

        #region Methods
        //--------------------------------------------------------------------
        // Methods
        //--------------------------------------------------------------------

        /// <summary>
        /// Releases managed (c# or .net) resources.
        /// </summary>
        protected override void ReleaseManagedResources()
        {
            base.ReleaseManagedResources();
            _data.PropertyChanging -= OnDataPropertyChanging;
            _data.PropertyChanged -= OnDataPropertyChanged;
        }

        private object GetName(SchemaBase schema) { return _data.DisplayName; }

        #endregion

        #region Events
        //--------------------------------------------------------------------
        // Events
        //--------------------------------------------------------------------

        #endregion
    }
}